# coding=UTF-8
from PIL import Image, ImageDraw
import os
import numpy as np
from pylab import *
import cv2
import imagedeal as imd
import carnotraing as ct
import charfeautre as cf
import plot  as plt
import imgdeal as cimd





# 图片内容提取
path = "/work/ocr/src.jpg"
# path ="/work/ocr/src.jpg"
# 图片灰度化
temp=cimd.regindectp(path);
corp=temp.split(",");
box=(int(corp[0]),int(corp[1]),int(corp[2]),int(corp[3]))
image = cv2.imread(path, cv2.IMREAD_COLOR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
retval, imarray = cv2.threshold(image, 170, 1, cv2.THRESH_BINARY)
imarray=imd.corpImage(imarray,box);
#plt.yulan(imarray)
#图片降噪
imarray=imd.clearNoise(imarray,4)

imags = imd.cutimage(imarray,  10, 20);
#图片归一
images=imd.batchresize(imags,14,22);

#获得图片预测结果
ct.predict(images)













# 图片二值化
# retval, imarray = cv2.threshold(image,170,255,cv2.THRESH_BINARY_INV)
# 图片水平垂直跳跃点截取图片
# imags = imd.corpCharBySkipPoint(imarray,  8, 8);
# 提取字符特征
# f1 = cf.outshape(imarray, 'left');
# f2 = cf.outshape(imarray, 'right')
# f3 = cf.outshape(imarray, 'top')
# f4 = cf.outshape(imarray, 'bottom')
# f5 = cf.inshape(imarray)
# v = ct.predict((f1, f2, f3, f4, f5))
